<?php

class View
{
	protected $file;
	protected $data = array();
	
	public function __construct($file)
	{
		$this->file = $file;
	}
	
	public function set($key, $valore)
	{
		$this->data[$key] = $valore;
	}
	
	public function get($key)
	{
		return $this->data[$key];
	}
	
	public function output()
	{
		if(!file_exists($this->file)){
			throw new Exception("Template " . $this->file . " non esiste.");
		}
		
		//Estraggo i dati da utilizzare nella view
		extract($this->data);
		
		//buffering e import
		ob_start();
		include($this->file);
		$output = ob_get_contents();
		ob_end_clean();
		
		//Stampo
		echo $output;
	}
	
}